<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>继承</title>
</head>

<body>

    <script>
        //借助构造函数实现
        function Parent1(){
            this.name = 'p1'
        }

        function Child1(){
            Parent1.call(this)
            this.type = 'c1'
        }

        var c1 = new Child1
        console.log(c1)

        //借助原型链实现
        function Parent2(){
            this.name = 'p2'
        }

        function Child2(){
            this.type = 'c2'
        }

        Child2.prototype = new Parent2

        var c2 = new Child2
        console.log(c2)

        //组合
        function Parent3(){
            this.name = 'p3'
        }

        function Child3(){
            Parent3.call(this)
            this.type = 'c3'
        }

        Child3.prototype = Parent3.prototype

        var c3 = new Child3
        console.log(c3)

        //最终
        function Parent4(){
            this.name = 'p4'
        }

        function Child4(){
            this.type = 'c4'
        }

        Child4.prototype = Object.create(new Parent4)
        Child4.prototype.constructor = Child4

        var c4 = new Child4
        console.log(c4)




    </script>

</body>

</html>